package com.yuan.vo;

import com.yuan.enums.ResponseEnum;
import lombok.Data;

import java.io.Serializable;
@Data
public class ResponseVO<T> implements Serializable {
    private static final long serialVersionUID = -1005863670741860901L;
    // 响应码
    private Integer code;

    // 描述信息
    private String message;

    // 响应内容
    private T data;

    private ResponseVO(ResponseEnum responseCode) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
    }

    private ResponseVO(ResponseEnum responseCode, T data) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = data;
    }

    private ResponseVO(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 返回成功信息
     * @param data 信息内容
     * @param <T>
     * @return
     */
    public static<T> ResponseVO success(T data) {
        return new ResponseVO<>(ResponseEnum.SUCCESS, data);
    }

    /**
     * 返回成功信息
     * @return
     */
    public static ResponseVO success() {
        return new ResponseVO(ResponseEnum.SUCCESS);
    }

    /**
     * 返回错误信息
     * @param responseCode 响应码
     * @return
     */
    public static ResponseVO error(ResponseEnum responseCode) {
        return new ResponseVO(responseCode);
    }
}
